package com.hu.controller;

import com.hu.entity.GetMajorOffered;
import com.hu.pojo.Major;
import com.hu.service.MajorService;
import com.hu.service.UniversityService;
import com.hu.utils.json.SimpleJson;
import com.hu.vo.MajorOfferedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ZhouKai
 * 2022/4/23 10:17
 */
@RestController
public class MajorController {
    @Autowired
    MajorService majorService;
    @Autowired
    UniversityService universityService;

    /**
     * 获取院校开设专业信息
     *
     * @param name 院校名称
     * @return Json 院校开设专业信息(集合)
     */
    @RequestMapping("/getMajorOffered")
    public SimpleJson getMajorOfferedVo(@RequestBody GetMajorOffered name) {
        Integer id = universityService.getUniversity(name.getName()).getId();
        List<MajorOfferedVo> majorOfferedVos = majorService.getMajorOfferedVo(id);
        return new SimpleJson(0, "成功", majorOfferedVos);
    }

    /**
     * 获取专业信息
     *
     * @param name 专业名称
     * @return Json 专业信息
     */
    @RequestMapping("/getMajor")
    public SimpleJson getMajor(@RequestBody GetMajorOffered name) {
        Major major = majorService.getMajor(name.getName());
        if(major==null) {
            return new SimpleJson(1,"失败");
        }
        return new SimpleJson(0,"成功",major);
    }
}
